package com.rongke.web.api;

import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.baomidou.mybatisplus.plugins.Page;
import com.rongke.commons.JsonResp;
import com.rongke.commons.PageDto;
import com.rongke.model.TdGjjPayInfo;
import com.rongke.service.TdGjjPayInfoService;
import org.apache.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.*;

/**
 * @TdGjjPayInfoController
 * @Controller
 * @version : Ver 1.0
 */
@RestController
@RequestMapping(value="/api/tdGjjPayInfo")
@Transactional
@CrossOrigin
public class TdGjjPayInfoController {
    private Logger log = Logger.getLogger(this.getClass());
    @Autowired
    private TdGjjPayInfoService tdGjjPayInfoService;

    /**
     * @添加
     * @param tdGjjPayInfo
     * @return 返回值JsonResp
     */
    @RequestMapping(value="/add", method = RequestMethod.POST)
    public JsonResp addTdGjjPayInfo(@RequestBody TdGjjPayInfo tdGjjPayInfo){
        log.debug("添加");
        tdGjjPayInfoService.insert(tdGjjPayInfo);
        return JsonResp.ok(tdGjjPayInfo);
    }

    /**
     * @修改
     * @param tdGjjPayInfo
     * @return 返回值JsonResp
     */
    @RequestMapping(value="/update", method = RequestMethod.POST)
    public JsonResp updateTdGjjPayInfo(@RequestBody TdGjjPayInfo tdGjjPayInfo){
        log.debug("修改");
        tdGjjPayInfoService.updateById(tdGjjPayInfo);
        return JsonResp.ok(tdGjjPayInfo);
    }
    /**
     * @根据id查找
     * @param id
     * @return 返回值JsonResp
     */
    @RequestMapping(value="/selectOne", method = RequestMethod.GET)
    public JsonResp selectTdGjjPayInfo(Long id){
        log.debug("查找");
        TdGjjPayInfo tdGjjPayInfo = tdGjjPayInfoService.selectById(id);
        return JsonResp.ok(tdGjjPayInfo);
    }


    @RequestMapping(value="/findByUserPage", method = RequestMethod.GET)
    public JsonResp findByUserPage(Long userId, Integer pageNo, Integer pageSize ){
        EntityWrapper<TdGjjPayInfo> entityWrapper = new EntityWrapper<>();
        Page page = new Page(pageNo,pageSize);
        entityWrapper.eq("user_id",userId);
        Page page1 = tdGjjPayInfoService.selectPage(page,entityWrapper);

        return JsonResp.ok(new PageDto(pageNo,pageSize,page1.getRecords(),page1.getTotal()));
    }

}
